
#ifndef  TABLE_H
#define  TABLE_H

#include "common.h"

class Records {
public:
    typedef std::pair<int, std::string> Record;

    class Iterator{
    public:
        Iterator(Records & records);
        ~Iterator();
        bool hasNext();
        Record * next();
    private:
        Records & records;
        int index;
    };

    Records();
    ~Records();

    Iterator iterator();

    Record* get(int index) const { return records[index]; }

    int size() { return records.size();}

    std::string toString() const;

    int pushBack(const int key, const  char * value);
    void clear();

private:
    std::vector<Record*> records;
};


class Table {
public:
    explicit Table(const std::string & name);
    virtual ~Table();

    virtual int init() {return 0;}
    virtual void deinit() {}

    const std::string getName() const { return name;}
    void setName(const std::string & name) { this->name = name; }

    virtual int insert(const int key, const char * value) = 0;
    virtual int update(const int key, const char * value) = 0;
    virtual int remove(const int key) = 0;
    virtual const char * find(const int key) const = 0;
    virtual Records * rangeScan(int offset, int count, bool isAscend, const std::string & indexName) const = 0;

    virtual std::string toString() const  = 0;
private:
    std::string name;
};


#endif   /* TABLE_H */
